<?php
$profiler = system_db::getAdapter()->getProfiler();
if($profiler->getEnabled()) {
	echo '<div id="debug">';
	echo '<h4>';
	echo 'QTY: <strong>' . $profiler->getTotalNumQueries() . '</strong>; ';
	echo 'MEMORY USED: <strong>' . (memory_get_usage() / 1024 / 1024) . '</strong> MB';
	echo '</h4>';	
	if(!!($list = $profiler->getQueryProfiles())) {
		echo '<ul>';
		foreach($list as $v) {
			$sql = $v->getQuery();
			$sql = $this->escape(preg_replace('/[\r\n]+/is', ' ', $sql));
			if(preg_match('/^DESCRIBE/is', $sql)) {
				$sql = '<font color="#666666">' . $sql . '</font>';
			} else {
				if($v->getElapsedSecs() > 0.01) {
					$color = $v->getElapsedSecs() < 0.1 ? 'blue' : 'red';
					$sql = '<font color="' . $color . '">' . $sql . '</font>';
				}
				if($v->getElapsedSecs() > 1) {
					$sql = '<strong>' . $sql . '</strong>';
				}
			}
			echo '<li>' . $sql . '; (<em>' . $v->getElapsedSecs() . '</em>)</li>';
		}
		echo '</ul>';
	}
	echo '<pre>' . session_id() . '<br/>' . print_r($_SESSION, true) . '</pre>';
	echo '</div>';
	echo "\n";
}
?>